package com.link.base.base.crowd.controller;

import com.link.base.base.crowd.model.CrowdTag;
import com.link.base.base.crowd.service.CrowdTagService;
import com.link.base.core.basic.util.CodeCleanUtils;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 人群圈选模块：消费者标签
 *
 * @author 何启谦
 * @date 2019-1-29
 */
@Controller
@RequestMapping("/link/crowdTag")
public class CrowdTagController extends BasicController<CrowdTag> {

    @Resource
    private CrowdTagService crowdTagService;

    @Override
    public BasicService<CrowdTag> getBasicService() {
        return crowdTagService;
    }

    /**
     * 查询组合成三层结构的标签
     *
     * @author 何启谦
     * @date 2019-1-29
     */
    @RequestMapping({"/queryTags"})
    @ResponseBody
    public Map<String, Object> queryTags() {
        Map<String, Object> result = CodeCleanUtils.cast(new HashMap(16));
        try {
            List<CrowdTag> list = crowdTagService.queryTags();
            result.put("success", true);
            result.put("rows", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("rows", new ArrayList<CrowdTag>());
            result.put("result", e.getMessage());
        }

        return result;
    }
}
